//
//  WineTableViewCell.m
//  TestWine
//
//  Created by 吴志勇 on 2020/2/26.
//  Copyright © 2020 wzy. All rights reserved.
//

#import "WineTableViewCell.h"
#import "Wine.h"
#import "CircleButton.h"

@interface  WineTableViewCell()
//@property (weak, nonatomic) IBOutlet UIButton *minusButton;
//@property (weak, nonatomic) IBOutlet UIButton *plusButton;
@property (weak, nonatomic) IBOutlet UIImageView *icon;
@property (weak, nonatomic) IBOutlet UILabel *wineName;
@property (weak, nonatomic) IBOutlet UILabel *money;
@property (weak, nonatomic) IBOutlet UILabel *countLabel;
@property (weak, nonatomic) IBOutlet CircleButton *plusButton;
@property (weak, nonatomic) IBOutlet CircleButton *minusButton;

@end


@implementation WineTableViewCell


/**** 使用方法修改圆角 ****/
//- (void)setUpCircleButton:(UIButton *)btn{
//    btn.layer.borderWidth = 1;
//    btn.layer.borderColor = [UIColor orangeColor].CGColor;
//    btn.layer.cornerRadius = btn.frame.size.width * 0.5;
//}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
//    [self setUpCircleButton:self.minusButton];
//    [self setUpCircleButton:self.plusButton];

}

 
- (void)setWine:(Wine *)wine{
    _wine = wine;
    self.icon.image = [UIImage imageNamed:wine.image];
    self.money.text = [NSString stringWithFormat:@"¥%@",wine.money];
    self.wineName.text =  wine.name;
    self.countLabel.text = [NSString stringWithFormat:@"%ld",wine.count];
    self.minusButton.enabled = (self.wine.count>0);
}
- (IBAction)plusButtonClick:(id)sender {
    _wine.count ++;
    self.countLabel.text = [NSString stringWithFormat:@"%ld",self.wine.count];
    
    self.minusButton.enabled = YES;
    
    
    [[NSNotificationCenter defaultCenter] postNotificationName:@"plusClickNotification" object:self.wine];
    
    
    /**** 实现代理方法 ****/
    //不需要实现全部方法是需要判断
//    if ([self.delegate respondsToSelector:@selector(WineTableViewCellDidPlusButton:)]) {
//        //    [self.delegate WineTableViewCellDidPlusButton:self];
//    }


    
}
- (IBAction)minusButtonClick {
    _wine.count --;
     self.countLabel.text = [NSString stringWithFormat:@"%ld",self.wine.count];
    if (self.wine.count == 0) {
        self.minusButton.enabled = NO;
    }
    
    
    [[NSNotificationCenter defaultCenter] postNotificationName:@"minusClickNotification" object:self.wine];
    
    /**** 实现代理方法 ****/
//    [self.delegate WineTableViewCellDidMinusButton:self];
}


@end
